package br.com.linhadotempo.struts2;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import br.com.linhadotempo.persistence.GerarEntityManager;
import br.com.linhadotempo.util.Sessao;
import br.com.linhadotempo.util.Util;
import br.com.taimlain.modelo.Usuario;

import com.opensymphony.xwork2.ActionSupport;

public class LinkAction extends ActionSupport {

	private Usuario usuario;

	/*
	 * Action para instanciar a EntityManagerFactory
	 */
	@Action(value = "instanceFactory")
	public void instanceFactory() {
		GerarEntityManager.getInstance();
	}

	/*
	 * Action para guiar o Jetty ao index.jsp
	 */
	@Action(value = "", results = { @Result(name = SUCCESS, location = Util.INDEX_JSP) })
	public String welcome() {
		Sessao.removeMessages();
		Sessao.put(LOGIN, false);
		return SUCCESS;
	}

	/*
	 * Action para pagina login.jsp
	 */
	@Action(value = "loginJsp", results = { @Result(name = SUCCESS, location = Util.LOGIN_JSP) })
	public String loginJsp() {
		Sessao.removeMessages();
		Sessao.put(LOGIN, false);
		return SUCCESS;
	}

	/*
	 * Action para pagina registro.jsp
	 */
	@Action(value = "registroJsp", results = { @Result(name = SUCCESS, location = Util.REGISTRO_JSP) })
	public String registroJsp() {
		Sessao.removeMessages();
		Sessao.put(LOGIN, false);
		return SUCCESS;
	}

	/*
	 * Action para pagina index.jsp
	 */
	@Action(value = "indexJsp", results = { @Result(name = SUCCESS, location = Util.INDEX_JSP) })
	public String indexJsp() {
		Sessao.removeMessages();
		return SUCCESS;
	}

	/*
	 * Action para pagina linhadotempo.jsp
	 */
	@Action(value = "linhadotempoJsp", results = { @Result(name = SUCCESS, location = Util.LINHADOTEMPO_JSP) })
	public String linhaDoTempoJsp() {
		Sessao.removeMessages();
		Sessao.put(LOGIN, true);
		return SUCCESS;
	}

	/*
	 * Action para pagina manterRegistro.jsp
	 */
	@Action(value = "manterregistroJsp", results = { @Result(name = SUCCESS, location = Util.MANTERREGISTRO_JSP) })
	public String manterRegistroJsp() {
		Sessao.removeMessages();
		Sessao.put(LOGIN, true);
		return SUCCESS;
	}
	
	/*
	 * Action para pagina apresentacao.jsp
	 */
	@Action(value = "apresentacaoJsp", results = { @Result(name = SUCCESS, location = Util.APRESENTACAO_JSP) })
	public String apresentacaoJsp() {
		Sessao.removeMessages();
		Sessao.put(LOGIN, true);
		return SUCCESS;
	}

	public Usuario getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	private static final long serialVersionUID = -6127672927283687142L;
}
